<?php

class Controller_Test extends Core_Controller_Web
{
    public function memcacheAction()
    {
        Model('Test')->memcache();

        return false;
    }

    public function redisAction()
    {
        $a = microtime(true);

        var_dump($a);
        var_dump($this->_redis->default->set('a', $a));
        var_dump($this->_redis->default->get('a'));
        var_dump($this->_redis->get('a'));

        var_dump($this->_redis->static->set('aaa', uniqid()));
        var_dump($this->_redis->static->get('aaa'));

        var_dump($this->_redis->blog->rpush('list', uniqid()));
        var_dump($this->_redis->blog->lrange('list', 0, -1));
        var_dump($this->_redis->blog->lpop('list'));
        var_dump($this->_redis->blog->lrange('list', 0, -1));

        return false;

    }

    public function slashesAction()
    {
        $data = array(
            'abc' => 'hello \'s boy',
            'abcd' => array(
                'key' => 'hello \'s boy',
            ),
        );

        var_dump($data);

        return false;
    }

    public function insertAction()
    {
        if ($this->isPost()) {

            $ip = 'abc\'efg';
            $setArr = array(
                'title' => $this->getx('title'),
                'content' => json_encode(array('key' => '我知道')),
                'ip' => $ip,
            );

            $db = Com_DB::get('test');
            var_dump($db->insert('my_blog', $setArr));

        } else {

            $form = <<<EOF
<form action="/test/pdo" method="POST">
    <input type="text" name="title" value="" />
    <input type="text" name="content" value="" />
    <input type="submit" />
</form>
EOF;
            echo $form;
        }

        return false;
    }

    public function whereAction()
    {
        if ($this->isPost()) {

            $title = $this->get('title');

            $whereArr = array(
                'title' => $title,
                'ip' => array('IN', array('撒旦法', 'abc\'efg')),
            );

            $whereSql = Com_DB::getWhereSql($whereArr);

            $db = Com_DB::get('test');

            echo '<pre>';
            print_r($db->fetchAll("select * from `my_blog` where {$whereSql}"));

        } else {

            $form = <<<EOF
<form action="/test/where" method="post">
    <input type="text" name="title" value="" />
    <input type="submit" />
</form>
EOF;
            echo $form;
        }

        return false;
    }
}